(() => {

	const content = document.querySelector('#content');
	const title = document.querySelector('#title');
	const tpl = `{{~it:v:i}}
	<tr data-list>
		<td class="" style="style="padding-right:0px"">
			<input data-feidao-type="check-list" type="checkbox" class="cursor-p" data-feidao-id="{{=v.task_id}}"/>
		</td>
		<td class="sorting">{{=v.task_name}}</td>
		<td class="sorting">{{=v.create_time}}</td>
		<td class="sorting">{{=v.start_time}}</td>
		<td class="sorting">{{=v.finish_time}}</td>
		<td class="sorting">{{=v.task_type}}</td>
		<td class="sorting">{{=v.task_status}}</td>
		<td class="sorting">{{=v.task_param}}</td>
	</tr>
	{{~}}`;

	// title.innerHTML = tpl_t;

	const data = [{
		task_id: '01',
		task_name: 'as',
		create_time: 'as',
		start_time: 'as',
		finish_time: 'as',
		task_type: 'as',
		task_status: 'as',
		task_param: 'as'
	}, {
		task_id: '02',
		task_name: 'adsdas',
		create_time: 'adsdas',
		start_time: 'adsdas',
		finish_time: 'adsdas',
		task_type: 'adsdas',
		task_status: 'adsdas',
		task_param: 'adsdas'
	}];

	var evalText = doT.template(tpl);
	console.log(evalText(data));
	content.innerHTML = evalText(data);
	return;
	$.ajax({
		type: 'GET',
		dataType: 'json',
		url: interface.task_find_list,
		data: {},
		success: (res) => {
			const dataEval = res;
			var evalText = doT.template(tpl);
			console.log(evalText(dataEval));
			content.innerHTML = evalText(dataEval);
		},
		error: (err) => {
			alert('服务出错，请刷新重试');
			console.error(err);
		}
	});



})();


// 表头多选
function check_all(e) {
	const stuts = document.querySelector('[data-feidao-id="check_all"]').checked;
	console.log(stuts);
	const c_list = document.querySelectorAll('[data-feidao-type="check-list"]');
	Array.from(c_list).forEach((ipt) => {
		ipt.checked = stuts;
	});
}

// 新增报错
function save() {
	const form = document.querySelector('[data-feidao-id="add_form"]');
	const task_name = form.querySelector('[task_name]').value;
	const create_time = form.querySelector('[create_time]').valueAsNumber;
	const start_time = form.querySelector('[start_time]').valueAsNumber;
	const task_type = form.querySelector('[task_type]').value;
	const task_status = form.querySelector('[task_status]').value;
	const task_param = form.querySelector('[task_param]').value;
	const data = { task_name, create_time, start_time, task_type, task_status, task_param };
	$.ajax({
		type: 'POST',
		dataType: 'json',
		url: interface.task_add,
		data,
		success: (res) => {
			alert('保存成功');
			window.location.reload();
		},
		error: (err) => {
			alert('服务出错，请刷新重试');
		}
	});
}

// 删除
function dele() {
	const c_list = document.querySelectorAll('[data-feidao-type="check-list"]:checked');
	if (c_list.length === 0) {
		alert('请选择要删除的数据');
		return;
	}
	const ids = Array.from(c_list).map((ipt) => {
		const id = ipt.getAttribute('data-feidao-id');
		return id;
	});

	$.ajax({
		type: 'POST',
		dataType: 'json',
		url: interface.task_del,
		data: { ids },
		success: (res) => {
			alert('保存成功');
			window.location.reload();
		},
		error: (err) => {
			alert('服务出错，请刷新重试');
		}
	});
}

// 修改
function edit() {
	alert('-- 修改 ---');
}